﻿
Public Class frmPost
    Private frmS As New dlgSelect
    Private strName As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'frmS = New dlgSelect
        'For i As Integer = 0 To AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut.Length - 1
        '    frmS.cmbPollution.Items.Add(AermodProject0.Aermod.Control.AllPolluts.AllSelectPollut(i).Name)
        'Next
        'If frmS.cmbPollution.Items.Count > 0 Then
        '    frmS.cmbPollution.SelectedIndex = 0
        'End If
        'frmS.cmbTime.SelectedIndex = 0
        'If frmS.ShowDialog() = Windows.Forms.DialogResult.OK Then '如果选择了，进行POST文件的分析
        '    Dim digOpen As New OpenFileDialog
        '    digOpen.Filter = "逐步值文件(*.bin)|*.bin"
        '    If digOpen.ShowDialog = Windows.Forms.DialogResult.OK Then
        '        If digOpen.FileName IsNot Nothing Then
        '            Dim filename As String = digOpen.FileName
        '            If filename.Contains(frmS.cmbPollution.Text) And filename.Contains(frmS.cmbTime.Text) Then
        '                With AermodProject0.Aermod
        '                    strName = filename
        '                    Dim nCount As Integer
        '                    '先找出总的数据记录的个数
        '                    Dim Post As New CAermod.PostResult
        '                    nCount = Post.GetDataCount(.Control, .Receptor, .Control.AllPolluts.AllSelectPollut(frmS.cmbPollution.SelectedIndex).Dispersion.DEPOS, strName, AermodProject0.Aermod.AermodVersion)
        '                    Dim strFirsTime As String = Post.GetFirstTime(strName)
        '                    Dim FistTime As DateTime = Post.StringToDate(strFirsTime)
        '                    '把所有时间列表出来
        '                    Me.lstTime.Items.Clear()
        '                    If frmS.cmbTime.Text = "1h" Then
        '                        For kTime As Integer = 0 To nCount - 1
        '                            Dim AddTime As New DateTime
        '                            AddTime = FistTime.AddHours(1 * kTime)
        '                            Me.lstTime.Items.Add(AddTime.ToString)
        '                        Next
        '                    ElseIf frmS.cmbTime.Text = "24h" Then
        '                        '由于在将字符串转换时多转换了一天，因此需要减一天。

        '                        For kTime As Integer = 0 To nCount - 1
        '                            Dim AddTime As New DateTime
        '                            AddTime = FistTime.AddDays(1 * (kTime - 1))
        '                            Me.lstTime.Items.Add(AddTime.ToString.Remove(AddTime.ToString.Length - 8, 8))
        '                        Next
        '                    End If
        '                    If Me.lstTime.Items.Count > 0 Then
        '                        Me.lstTime.SelectedIndex = 0
        '                    End If
        '                End With
        '            Else
        '                MessageBox.Show("选择的文件错误!请重新选择。")
        '            End If
        '        End If
        '    End If
        'End If
    End Sub

    Private Sub frmPost_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cmbReceptor.SelectedIndex = 0
        Me.cmbGrid.SelectedIndex = 0
        Me.EFlex1.Rows.Count = 1

        EFlex1.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
        EFlex1.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.Columns
        EFlex1.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
    End Sub

    Private Sub cmbReceptor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbReceptor.SelectedIndexChanged
        If Me.cmbReceptor.SelectedIndex = 0 Then
            Me.cmbGrid.Enabled = False
        Else
            Me.cmbGrid.Enabled = True
        End If
        showResult()
    End Sub
    Private Sub showResult()
        'Me.EFlex1.Clear()
        'If Me.cmbReceptor.SelectedIndex >= 0 And Me.lstTime.SelectedIndex >= 0 Then
        '    With AermodProject0.Aermod
        '        Dim nIndex As Integer = Me.lstTime.SelectedIndex
        '        Dim Post As New CAermod.PostResult
        '        Dim OnePostBin As CAermod.PostFineBinResult = Post.GetDataPostBin(.Control, .Receptor, .Control.AllPolluts.AllSelectPollut(frmS.cmbPollution.SelectedIndex).Dispersion.DEPOS, nIndex, strName, "09292")
        '        If cmbReceptor.SelectedIndex = 0 Then '关心点
        '            Me.EFlex1.Rows.Count = AermodProject0.Aermod.Receptor.DiscCarts.Length + 1
        '            Me.EFlex1.Cols.Count = 6
        '            Me.EFlex1.Item(0, 0) = "序号"
        '            Me.EFlex1.Item(0, 1) = "关心点名称"
        '            Me.EFlex1.Item(0, 2) = "X"
        '            Me.EFlex1.Item(0, 3) = "Y"
        '            Me.EFlex1.Item(0, 4) = "Z"
        '            Me.EFlex1.Item(0, 5) = "浓度[mg/m^3]"
        '            For i As Integer = 0 To OnePostBin.m_CareData.Length - 1
        '                Me.EFlex1.Item(i + 1, 0) = i + 1
        '                Me.EFlex1.Item(i + 1, 1) = AermodProject0.Aermod.Receptor.DiscCarts(i).Name
        '                Me.EFlex1.Item(i + 1, 2) = AermodProject0.Aermod.Receptor.DiscCarts(i).Xcoord
        '                Me.EFlex1.Item(i + 1, 3) = AermodProject0.Aermod.Receptor.DiscCarts(i).Ycoord
        '                Me.EFlex1.Item(i + 1, 4) = AermodProject0.Aermod.Receptor.DiscCarts(i).Zelev
        '                Me.EFlex1.Item(i + 1, 5) = OnePostBin.m_CareData(i).con / 1000
        '            Next
        '            Me.EFlex1.AutoSizeCols()
        '        Else '网格点
        '            Me.EFlex1.Item(0, 0) = "Y\X"
        '            If Me.cmbGrid.SelectedIndex = 0 Then '主网格
        '                If .Receptor.SubGridCart(0).Selected = True Then
        '                    Me.EFlex1.Rows.Count = .Receptor.SubGridCart(0).Ynum + 1
        '                    Me.EFlex1.Cols.Count = .Receptor.SubGridCart(0).Xnum + 1
        '                    For i As Integer = 0 To .Receptor.SubGridCart(0).Ynum - 1
        '                        For j As Integer = 0 To .Receptor.SubGridCart(0).Xnum - 1
        '                            Me.EFlex1.Item(i + 1, j + 1) = OnePostBin.m_GridData(i, j).con / 1000
        '                            Me.EFlex1.Item(0, j + 1) = .Receptor.SubGridCart(0).Xinit + .Receptor.SubGridCart(0).Xdelta * j
        '                            Me.EFlex1.Item(1 + i, 0) = .Receptor.SubGridCart(0).Yinit + .Receptor.SubGridCart(0).Ydelta * (.Receptor.SubGridCart(0).Ynum - 1 - i)
        '                        Next
        '                    Next
        '                    Me.EFlex1.AutoSizeCols()
        '                Else
        '                    MessageBox.Show("没有主网格的数据，请查看方案是否计算了主网格!")
        '                End If
        '            Else '嵌套网格
        '                Dim iSelected As Integer = Me.cmbSubGrid.SelectedIndex
        '                If iSelected >= 0 Then

        '                    Me.EFlex1.Rows.Count = .Receptor.SubGridCart(iSelected).Ynum + 1
        '                    Me.EFlex1.Cols.Count = .Receptor.SubGridCart(iSelected).Xnum + 1
        '                    For i As Integer = 0 To .Receptor.SubGridCart(iSelected).Ynum - 1
        '                        For j As Integer = 0 To .Receptor.SubGridCart(iSelected).Xnum - 1
        '                            Me.EFlex1.Item(i + 1, j + 1) = OnePostBin.m_SubGridData(iSelected)(i, j).con / 1000
        '                            Me.EFlex1.Item(0, j + 1) = .Receptor.SubGridCart(iSelected).Xinit + .Receptor.SubGridCart(iSelected).Xdelta * j
        '                            Me.EFlex1.Item(1 + i, 0) = .Receptor.SubGridCart(iSelected).Yinit + .Receptor.SubGridCart(iSelected).Ydelta * (.Receptor.SubGridCart(iSelected).Ynum - 1 - i)
        '                        Next
        '                    Next
        '                    Me.EFlex1.AutoSizeCols()
        '                End If
        '            End If
        '        End If
        '    End With

        'End If
    End Sub

    Private Sub cmbGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbGrid.SelectedIndexChanged
        If Me.cmbGrid.SelectedIndex = 1 And Me.cmbGrid.Enabled = True Then
            Me.cmbSubGrid.Enabled = True
        Else
            Me.cmbSubGrid.Enabled = False
        End If
        showResult()
    End Sub

    Private Sub lstTime_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstTime.SelectedIndexChanged
        showResult()
    End Sub

    Private Sub cmbSubGrid_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSubGrid.SelectedIndexChanged
        showResult()
    End Sub
End Class